import yaml
import requests
import logging
from string import Template
from daofeng_api_demo.api.base_api import BaseApi


class GetToken(BaseApi):
    _corpid = 'ww2836d3b555b37fb4'
    _corpsecret = 'XsWLb_vAe9XI5JsmtvCOc4PXqMu9KP1xF91ZDpjHtPk'

    def template(self):
        '''
        yaml文件变量替换
        :return:
        '''

        data = {
            'corpid': self._corpid,
            'corpsecret': self._corpsecret
        }
        with open('../api/get_token.yaml') as f:
            re = Template(f.read()).substitute(data)
            return yaml.safe_load(re)

    def get_token(self):
        req = self.template()
        r = self.requests_http(req)
        print(r.json())
        return r

if __name__ == '__main__':
    q = GetToken()
    q.template()